<?php
/**
 * Created by PhpStorm.
 * User: yuyiwen
 * Date: 2018/10/19
 * Time: 下午5:29
 */

$dsn = 'mysql:dbname=yii2basic;host=127.0.0.1';
$usr = 'root';
$pwd = '123456';
$pdo = new PDO($dsn , $usr , $pwd);

$pdo->beginTransaction();

try{
    $sql = 'UPDATE `member` SET `moneys` = `moneys` - 10 WHERE `id` = 1';
    $pdo->exec($sql);
    $sql = 'UPDATE `member` SET `moneys` = `moneys` + 10 WHERE `id` = 2';
    $pdo->exec($sql);
    $pdo->commit();
}catch (Exception $e) {
    $pdo->rollBack();
    echo $e->getMessage();
}